<?php
namespace Core\MVC;

class Dispatcher implements IDispatcher {
	
	/**
	 * @var \Core\MVC\IRouter
	 */
	private $router;
	private $viewHandler;
	
	public function handleRequest() {
                session_start(); // TODO; CLEANUP!
            
		$requestURI = explode ("?", substr($_SERVER["REQUEST_URI"], 1));
		$requestURI = $requestURI[0];
		
		list($controller, $method, $args) = $this->router->resolve($requestURI, $_SERVER['REQUEST_METHOD']);
		$modelMap = $method->invokeArgs($controller, $args);
		$this->viewHandler->render($modelMap);
	}
	
	public function setRouter($router) {
		$this->router = $router;
	}
	
	public function setViewHandler($viewHandler) {
		$this->viewHandler = $viewHandler;
	}
	
};